package actions;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;

import org.jfree.chart.plot.XYPlot;

import ui.CurrentZoom;
import ui.OSMPanel2;
import ui.SpeedPanel;

public class ZoomController implements PropertyChangeListener {

	private final CurrentZoom currentZoom;
	private final OSMPanel2 mapPanel;
	private final SpeedPanel speedPanel;

	public ZoomController(CurrentZoom currentZoom, OSMPanel2 mapPanel, SpeedPanel speedPanel) {
		this.currentZoom = currentZoom;
		this.mapPanel = mapPanel;
		this.speedPanel = speedPanel;
		
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if (evt.getPropertyName().equals(Settings.getInstance().RANGE_CHANGE)) {
			long[] hilite = (long[]) evt.getNewValue();
			//System.out.println(new Date() + "   Hilite " + new Date(hilite[0]) + " " + new Date(hilite[1]));
			currentZoom.setTimeStart(hilite[0]);
			currentZoom.setTimeEnd(hilite[1]);
			mapPanel.repaint();
			XYPlot xyPlot = speedPanel.getPlot();
			xyPlot.getRangeAxis().setAutoRange(true); 
			speedPanel.repaint();
		}
	}
	
}